//
//  WLMainViewController.swift
//  weibo
//
//  Created by 刁 海瑞 on 16/8/8.
//  Copyright © 2016年 毋磊. All rights reserved.
//

import UIKit

class WLMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let wlTabBar = WLTabBar()
        
        wlTabBar.composeButtonClosure = { [weak self] in
            
            print("我是闭包调用过来的")
        }
        
        setValue(wlTabBar, forKey: "tabBar")

        view.backgroundColor = UIColor.redColor()
        
        addChildViewController(WLHomeTableViewController(), imageName: "tabbar_home", title: "首页")
        addChildViewController(WLDiscoverTableViewController(), imageName: "tabbar_discover", title: "发现")
        addChildViewController(WLMessageTableViewController(), imageName: "tabbar_message_center", title: "消息")
        addChildViewController(WLProfileTableViewController(), imageName: "tabbar_profile", title: "我的")
        
    }
    
  

    func addChildViewController(childController: UIViewController,imageName: String,title: String) {
        
        childController.tabBarItem.image = UIImage(named: imageName)
//        设置选中状态
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        childController.title = title
//        设置字体颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor .orangeColor()], forState: .Selected)
//        设置字体大小
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont .systemFontOfSize(14)], forState: .Normal)
        
        let nav = UINavigationController(rootViewController: childController)
        
        addChildViewController(nav)
        
        
    }

   

}
